//
//  CZStatusTop.swift
//  weibo27
//
//  Created by mac on 16/4/19.
//  Copyright © 2016年 it.cast. All rights reserved.
//

import UIKit

// MARK: 顶部的视图
class CZStatusTop: UIView {

    var statusViewModel:CZStatusViewModel?{
        didSet{
            
            //头像
            iconView.sd_setImageWithURL(statusViewModel?.userProfileUrl, placeholderImage: statusViewModel?.userDefaultImage)
            //昵称
            nameLabel.text = statusViewModel?.userStatus.user?.screen_name
            //vip
            memberIconView.image = statusViewModel?.userMemberImage
            /// 会员
            vipIconView.image = statusViewModel?.userVipImage
            /// 时间
            timeLabrl.text = "刚才"
            /// 来源
            sourceLabrl.text = "传智播客"
            
        }
    }
    
    /// 构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    /// 头像
    private lazy var  iconView:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    /// 昵称
    private lazy var nameLabel:UILabel = UILabel(title: "老王", fontSize: 15)
    /// vip标志
    private lazy var memberIconView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    /// 认证图标
    private lazy var vipIconView:UIImageView = UIImageView(image: UIImage (named: "avatar_vip"))
    /// 时间
    private lazy var timeLabrl:UILabel = UILabel(title: "刚刚", fontSize: 11)
    /// 来源
    private lazy var sourceLabrl:UILabel = UILabel(title: "来源", fontSize: 11)
    
}

// MARK: - 设置界面
extension CZStatusTop{
    
    private func setupUI(){
        
//        backgroundColor = UIColor.init(white: 0.95, alpha: 1.0)
        
        // 1添加控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabrl)
        addSubview(sourceLabrl)
        
        // 2设置frame
        /// iconView的约束
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.width.equalTo(StatusCellIconWidth)
            make.height.equalTo(StatusCellIconWidth)
        }
        /// nameLabel的约束
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
            make.top.equalTo(iconView.snp_top)
        }
        /// nameLabel的约束
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
            make.top.equalTo(nameLabel.snp_top)
        }
        /// vipIconView的约束
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        /// timeLabrl的约束
        timeLabrl.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        /// sourceLabrl的约束
        sourceLabrl.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabrl.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        
    }
    
}


